let vm = new Vue({
    el: "#content",
    data: {
        username: "",
        userList: [], // 当前页数据
        totalPage: "", //总页数
        page: 1,       //当前页
        focusIds: [],   //当前用户关注的人
        loginUser: {}
    },
    methods: {
        findPageUser: function (page) {
            if (this.totalPage == 0) {
                this.totalPage = 1;
            }
            if (page < 1) {
                layer.msg("已经是第一页了");
                return;
            }
            if (page > this.totalPage) {
                layer.msg("已经是最后一页了");
                return;
            }
            axios({
                method: "get",
                url: `/user/findPageUser/${page}`,
                params: {username: this.username}
            }).then(res => {
                if (res.data.flag) {
                    this.userList = res.data.data.pageResult.rows;// 当前页数据
                    this.totalPage = res.data.data.pageResult.totalPage;//总页数
                    this.focusIds = res.data.data.focusIds;//当前用户关注的人
                    this.page = page;//当前页

                    for (let i = 0; i < this.userList.length; i++) {
                        if (this.focusIds.indexOf(this.userList[i].id) === -1) {
                            this.userList[i].checkFocus = false;
                        } else {
                            this.userList[i].checkFocus = true;
                        }
                    }
                } else {
                    layer.msg(res.data.message);
                }
            });
        },
        detail: function (user) {
            if (user.isSecret == 0) {
                layer.msg("对方设置了私秘！");
                return;
            }
            sessionStorage.setItem("userId", user.id);
            location.href = "/html/user_detail.html";
        },
        focus: function (userId, e) {
            if (userId == this.loginUser.id) {
                e.preventDefault();
                layer.msg("您不可以关注您自己");
                return;
            }
            axios({
                method: "get",
                url: `/user/focus/${userId}`
            }).then(res => {
                layer.msg(res.data.message);
            });
        }
    },
    created: function () {
        this.loginUser = JSON.parse(localStorage.getItem("loginUser"));
        this.findPageUser(1)
    }
})